<?php

namespace app\services;

use plugin\admin\app\model\SystemNoticeTemplate;

class SystemNoticeTemplateService
{
    public static function build($scene, $params)
    {
        $defaultValue = [
            'title' => '',
            'content' => '',
            'desc' => ''
        ];

        $template = SystemNoticeTemplate::select(['title', 'desc', 'content'])->where('scene', $scene)->first();

        if (!$template) {
            return $defaultValue;
        }

        $template = $template->toArray();

        foreach ($params as $key=>$param) {
            $template['content'] = str_replace("{{param$key}}", $param, $template['content']);
        }

        return array_merge($defaultValue, $template);
    }

}